package com.sunplus.system.controller.system.app;

import com.sunplus.common.core.domain.AjaxResult;
import com.sunplus.common.core.domain.entity.SysUser;
import com.sunplus.common.core.domain.model.LoginBody;
import com.sunplus.common.utils.SecurityUtils;
import com.sunplus.common.utils.StringUtils;
import com.sunplus.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.UUID;

/**
 * 登录验证
 */
@RestController
@RequestMapping("/app/")
public class AppRegisterController {

    @Autowired
    private SysUserMapper sysUserMapper;


    @PostMapping("register")
    public AjaxResult register(LoginBody loginBody) {
        if (loginBody != null) {
            SysUser checkUser = sysUserMapper.selectUserByUserNameAndType(loginBody.getUsername());
//        SysUser sysUser = sysUserMapper.selectUserByMobile(loginBody.getUsername());
            if(checkUser != null){
                return AjaxResult.error("该用户已在此平台注册");
            }
            SysUser sysUser=new SysUser();
            sysUser.setPID(UUID.randomUUID().toString());
            sysUser.setUserID(loginBody.getUsername());
            sysUser.setMobile(loginBody.getUsername());
            sysUser.setUserType_Sel("3");
            sysUser.setPassWord(SecurityUtils.encryptPassword(loginBody.getPassword()));
            sysUser.setCreateTime(new Date());
            sysUser.setCreateUser("app");
            sysUserMapper.insertUser(sysUser);
            return AjaxResult.success();
        } else {
            return AjaxResult.error("注册用户失败");
        }
    }


}
